from django.db import models

# Create your models here.
class BookInfo(models.Model):

    bookName = models.CharField(max_length=10,unique=True,verbose_name="书籍名字")
    pub_date = models.DateTimeField(null=True,verbose_name="出版时间")
    readCount = models.IntegerField(default=0,verbose_name="阅读量")
    commentCount = models.IntegerField(default=0,verbose_name="评论数")
    is_delete = models.BooleanField(default=False,verbose_name="是否被删除")

    #peopleinfo_set=[PeopleInfo,PeopleInfo,PeopleInfo]

    def __str__(self):
        return self.bookName

    class Meta:
        db_table = 'bookinfo'
        verbose_name = "书籍管理"

class PeopleInfo(models.Model):
    # 定义一个有序字典
    GENDER_CHOICES = (
        (1,'male'),
        (2,'female')
    )
    name = models.CharField(max_length=20,unique=True,verbose_name="人物姓名")
    gender= models.SmallIntegerField(choices=GENDER_CHOICES,default=1,verbose_name="性别")
    description=models.CharField(max_length=100)
    is_delete = models.BooleanField(default=False)

    # 系统会自动地添加 _id
    book = models.ForeignKey(BookInfo,on_delete=models.CASCADE)

    class Meta:
        db_table = 'peopleinfo'
        verbose_name = "顾客信息"

    def __str__(self):
        return self.name